#include <stdlib.h>
#include <assert.h>
#include "character.h"
#include "point2.h"
#include "animation.h"
#include "source.h"
#include "frame.h"
#include "rect.h"
#include "ai.h"

Character::Character(){

	cur_animation =NULL;
	velocity =NULL;
	position =NULL;
	orientation =NULL;
	src_death =NULL;
	src_move =NULL;
	src_fall =NULL;
	ai =NULL;
}

Character::~Character(){

	delete orientation;	
	orientation =NULL;

	delete position;	
	position =NULL;

	delete velocity;
	velocity =NULL;

	delete src_death;
	src_death =NULL;

	delete src_move;
	src_move =NULL;

	delete src_fall;
	src_fall =NULL;

	delete ai;
	ai =NULL;

	// do not delete!!!
	cur_animation =NULL;
}

// return center of the character's body
void Character::getCenter(Point2* center){

	assert(center);
	Rect* rect =cur_animation->frames[cur_animation->cur_frame]->body;

	center->x =position->x + rect->xLo + (rect->xHi -rect->xLo)*0.5f; // /2
	center->y =position->y + rect->yLo + (rect->yHi -rect->yLo)*0.5f; // /2
}

// return x-center of the character's body
float Character::getCenterX(){

	Rect* rect =cur_animation->frames[cur_animation->cur_frame]->body;

	return position->x + rect->xLo + (rect->xHi -rect->xLo)*0.5f; // /2
}

// return y-center of the character's body
float Character::getCenterY(){

	Rect* rect =cur_animation->frames[cur_animation->cur_frame]->body;

	return position->y + rect->yLo + (rect->yHi -rect->yLo)*0.5f; // /2
}